home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3183 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  47 lines

  1. Path: populus.slu.se!newsmgr
  2. From: Thomas.Johansson@stax.slu.se (Thomas Johansson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q]Assigning function pointer in C/C++.
  5. Date: 22 Jan 1996 15:18:06 GMT
  6. Organization: SLU Umeσ
  7. Message-ID: <4e09re$kit@populus.slu.se>
  8. References: <DL3JJu.5nB.0.queen@torfree.net> <4doc42$gsb@bmdhh222.bnr.ca> <ALUN.CHAMPION.96Jan19113523@g7240065.bridge.bst.bls.com>
  9. NNTP-Posting-Host: b93.resgeom.slu.se
  10. X-Newsreader: WinVN 0.92.1
  11.  
  12. In article <ALUN.CHAMPION.96Jan19113523@g7240065.bridge.bst.bls.com>, Alun.Champion@bridge.bst.bls.com (Alun Champion) says:
  13. >
  14. > -- snip
  15. >
  16. >Huh?
  17. >
  18. >You can have pointers to member functions providing you know what class (or base
  19. >class) you are going to be assigning functions from.
  20. >
  21. >   int (A::*p)(void);
  22. >
  23. >declares p as a pointer to an A member function which takes nothing and returns
  24. >an int. The usage of p requires an object or pointer to an object of
  25. >type A or derived from A. i.e:
  26. >  
  27. >   A a;
  28. >   int z = (a.*p)();    // Uses '.*' operator.
  29. >or
  30. -- snip
  31.  
  32. Is there any way that you can declare a variable to hold the resulting pointer,
  33. or must it be 'used' right away ?
  34.  
  35. something like
  36.  
  37.   typdef int (A::*p)(void) Fp;     // Fp is a type of 'pointer to member function'
  38.  
  39.   Fp f = (a.*p);                   // the object a (of class A) has a member p
  40.  
  41.   int z = f();
  42.  
  43. I cannot make this work with Borland 4.5.
  44.  
  45. Regards
  46. Thomas
  47.